
var vue;
function vue_init() {
    vue = new Vue({
        delimiters:['{!', '!}'],
        el: "#market-app",
        data: {
            CoinDetail: {},
            // flag: false
            coin_type:"",
            is_not_select_all: false,
            coin_type : "",
            up_coin_type: "",
            history_list: [],
            jsonobj:[],
            dep_his_detail: {},
            wit_his_detail: {},
        },
        methods:{
            init: function () {
                /* 根据URL上的参数获取类型 */
                var params = get_url_params();
                this.coin_type = params.coin_type;
                // console.log(this.coin_type);
                this.get_history_list_all();
            },
            /* 转换选择全部或者部分 */
            select_all: function(){
                if (this.is_not_select_all){
                    this.is_not_select_all = false
                }else{
                    this.is_not_select_all = true
                }
                this.show_history()
            },
            show_history: function() {
                jsonobj = this.jsonobj
                var history_list = []
                for (var i= 0; i < jsonobj.length; i++) {
                    var info = jsonobj[i]
                    if (this.is_not_select_all){
                        if (this.coin_type != info.coin_type)
                        {
                            continue
                        }
                    }
                    //console.log(info.coin_type)
                    var row = {}
                    row.uuid = info.uuid
                    row.coin_type = info.coin_type
                    row.up_coin_type = row.coin_type.toUpperCase()

                    row.price = info.price
                    /* 数量 */
                    row.amount = info.amount
                    /* 时间 */
                    row.create_time = date_format_iso(info.create_time)
                    row.show_detail = false

                    /* 状态 */
                    if (info.status === 2){
                        row.status = '成功'
                        if (info.type == 22 || info.type == 21){
                            row.show_detail = true
                        }

                    }else if (info.status === 1) {
                        row.status = '申请中'
                    }
                    /* 类型 */
                    if (info.type === 22){
                        row.is_withdrawal = true;
                        row.is_deposit = false;
                        row.is_send = false;
                        row.type = '提现';
                    }else if(info.type === 21){
                        row.is_withdrawal = false;
                        row.is_deposit = true;
                        row.is_send = false;
                        row.type = '充值'
                    }else if (info.type === 26){
                        row.is_withdrawal = false;
                        row.is_deposit = false;
                        row.is_send = true;
                        row.type = '系统送币'
                    }
                    history_list.push(row)
                }
                this.history_list = history_list
            },
            /* 请求历史记录 */
            get_history_list_all: function () {
                params = {coin_type: this.coin_type}
                if (!this.is_not_select_all){
                    params = {}
                }
                // console.log(params)
                $.post("/btc/userinfo_get_finance", params,
                (data) => {
                    //console.log(data);
                    var jsonobj = data
                    this.jsonobj = jsonobj
                    this.show_history()
                    // console.log(this.history_list);
                });
            },

            /* 根据ID获取详情的数据 */
            show_detail: function (type, uuid) {
                /* 充值的情况 */
                if(type === "充值"){
                   $.post("/btc/get_deposites", {
                        uuid: uuid
                    }, (res) => {
                        // console.log(res);
                        this.dep_his_detail = res;
                        layer.open({
                            className:'PromptBox',
                            type: 1,
                            content: $("#show_dep_detail").html(),
                            anim: 'up',
                            style: 'background:none; left:0; top:0; width:100%; height:100%;  -webkit-animation-duration: .5s; animation-duration: .5s;'
                        });
                        $("#dep_his_tim").html(date_format_iso(this.dep_his_detail.confirm_time));
                        $("#dep_his_add").html(this.dep_his_detail.address);
                        $("#dep_his_id").html(this.dep_his_detail.txid).attr("href", "https://etherscan.io/tx/" + this.dep_his_detail.txid);
                    });
                }
                if(type === "提现") {
                    /* 提现的情况 */
                    $.post("/btc/get_withdrawes", {
                        uuid: uuid
                    }, (res) => {
                        // console.log(res);
                        this.wit_his_detail = res;
                        layer.open({
                            className:'PromptBox',
                            type: 1,
                            content: $("#show_wit_detail").html(),
                            anim: 'up',
                            style: 'background:none; left:0; top:0; width:100%; height:100%;  -webkit-animation-duration: .5s; animation-duration: .5s;'
                        });
                        $("#wit_his_tim").html(date_format_iso(this.wit_his_detail.withdraw_time));
                        $("#wit_his_fee").html(this.wit_his_detail.fee);
                        $("#wit_his_add").html(this.wit_his_detail.address);
                        $("#wit_his_id").html(this.wit_his_detail.txid).attr("href", "https://etherscan.io/tx/" + this.dep_his_detail.txid);
                    });
                }

            },

        },
        created () {
            this.is_not_select_all = true
        }

    });
    vue.init();
}

$(function () {
    vue_init();
})
